<?php

namespace App\Http\Controllers\Index;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Resources\Index\Summary\DataResource;
use App\Http\Resources\Index\Summary\MonitoringResource;
use App\Services\Postman\GameService as PostmanGameService;
use App\Services\Index\SummaryService;

class SummaryController extends Controller
{

    /**
     * 获取实时数据
     */
    public function monitoring(Request $request)
    {
        $codes = collect();
        if (!$request->user()->isSuperAdmin()) {
            $codes = $request->user()->getTreePermissionOrgs()->pluck('code');
            $codes->isEmpty() && $codes->push('0');
        }

        $result = PostmanGameService::post(PostmanGameService::URI_REALTIME_PLAYER_INFO,
            ['plat_codes' => $codes->toArray()]
        );

        return new MonitoringResource($result['infos']);
    }

    /**
     * 概要统计【注册人数】
     */
    public function playerRegister(Request $request)
    {
        list ($collection, $total) = SummaryService::make()->playerRegister($request);

        return DataResource::make($collection)->setAttribute('total', $total);
    }

    /**
     * 概要统计【游戏人数】
     */
    public function playerGame(Request $request)
    {
        list ($collection, $total) = SummaryService::create()->playerGame($request);

        return DataResource::make($collection)->setAttribute('total', $total);
    }

    /**
     * 概要统计【新增游戏人数】
     */
    public function playerGameNew(Request $request)
    {
        list ($collection, $total) = SummaryService::make()->playerGameNew($request);

        return DataResource::make($collection)->setAttribute('total', $total);
    }

    /**
     * 概要统计【平台收益】
     */
    public function amount(Request $request)
    {
        list ($collection, $total) = SummaryService::create()->amount($request);

        return DataResource::make($collection)->setAttribute('total', $total);
    }
}
